import { createRouter, createWebHistory } from 'vue-router';
import NProgress from 'nprogress';
import 'nprogress/nprogress.css';

import { appRoutes } from './routes';
import { REDIRECT_MAIN, NOT_FOUND_ROUTE } from './routes/base';
import createRouteGuard from './guard';

// 进度条
NProgress.configure({ showSpinner: false });

// 创建路由
const router = createRouter({
    history: createWebHistory(),
    routes: [
        {
            path: '/',
            redirect: 'home',
        },
        {
            path: '/user/center',
            name: 'UserCenter',
            component: () => import('@/views/user/center/index.vue'),
            meta: {
                locale: '用户中心',
                requiresAuth: true,
                hideInMenu: false,
            },
        },
        ...appRoutes
    ],
    scrollBehavior() {
        return { top: 0 };
    },
    // @ts-ignore
    REDIRECT_MAIN,
    // @ts-ignore
    NOT_FOUND_ROUTE,
});

createRouteGuard(router);

export default router;
